package com.lt.crm.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lt.crm.pojo.Product;
import com.lt.crm.service.ProductService;
import javax.annotation.Resource;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;



@Controller
@RequestMapping("/product")
public class ProductController {

    @Resource
    ProductService productService;


    @RequestMapping("/list")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") Integer pageIndex,
                       @RequestParam(defaultValue = "",required = false) String prodName,
                       @RequestParam(defaultValue = "",required = false)String prodType,
                       @RequestParam(defaultValue = "",required = false)String prodBatch) {
//        Sort sort = new Sort(Sort.Direction.ASC, "prodId");
//        Pageable pageable = PageRequest.of(pageIndex - 1, 3, sort);
        Page<Product> page = new Page<>(pageIndex, 5);
        Page<Product> page2 = productService.findAllByPage(page, prodName, prodType, prodBatch);
        model.addAttribute("productPage",page2);
        model.addAttribute("prodName",prodName);
        model.addAttribute("prodType",prodType);
        model.addAttribute("prodBatch",prodBatch);
        return "product/list";
    }

}
